package com.springboot.dubbo.user.provider;

import com.springboot.dubbo.user.dto.UserInfoDTO;
import com.springboot.dubbo.user.dto.UserQueryDTO;
import com.springboot.dubbo.user.api.IUserProvider;
import com.springboot.dubbo.user.mapper.ICallRecordMapper;
import com.springboot.dubbo.user.service.CallRecordServiceImpl;
import io.seata.core.context.RootContext;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description: TODO：未加类注释说明
 * @Author 杨冬冬
 * @Date 2021/6/30 0030 9:14
 **/
@Component
//version = 服务提供者的版本(如多态服务者集群时，其中1台已经升级为最新版本，那么消费者可通过版本号进行新版调用)
@DubboService(group = "dubbo-demo", version = "0.0.2")
public class UserProvider implements IUserProvider {

    @Autowired
    private CallRecordServiceImpl callRecordService;

    @Override
    public UserInfoDTO getUser() {
        UserInfoDTO user = new UserInfoDTO();
        user.setId("aaa");
        user.setName("bbb");
        return user;
    }

    @Override
    public List<UserInfoDTO> queryList(UserQueryDTO dto) {
        UserInfoDTO user = new UserInfoDTO();
        user.setId("aaa");
        user.setName("bbb");
        UserInfoDTO user1 = new UserInfoDTO();
        user1.setId("aaa2");
        user1.setName("bbb2");
        List<UserInfoDTO> list = new ArrayList<>();
        list.add(user);
        list.add(user1);
        return list;
    }

    @Override
    public void insert() throws Exception {
        String xid = RootContext.getXID();
        System.out.println(xid);
        callRecordService.insert();
    }
}
